﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;
using iLangl.LanguageWire.Managers;

namespace iLangl.LanguageWire.DAL.LanguageWireDAL.MockupStorage
{
	public class MockupContactDAL : MockupBaseDAL, IContactDAL
	{
		#region IContactDAL Members

		public void CreateContact(Contact contact, bool isPrimary)
		{
			if (contact == null)
				return;


			if (!string.IsNullOrEmpty(contact.TPIdentity))
				return;

			dtoMockupStorage.ContactRow contactRow = Storage.Contact.FindById(contact.Id);

			bool isNew = (contactRow == null);

			if (isNew)
			{
				contactRow = Storage.Contact.NewContactRow();
			}

			contactRow.CompanyId = new Guid(contact.Company.Id);
			contactRow.EMail = contact.Email;
			contactRow.FirstName = contact.FirstName;
			contactRow.Id = contact.Id;
			contactRow.LastName = contact.LastName;
			contactRow.Phone = contact.Phone;
			contactRow.Title = contact.Title;
			contactRow.IsPrimary = isPrimary;

			if (isNew)
			{
				Storage.Contact.AddContactRow(contactRow);
			}

			AcceptChanges();
			int customerId = contactRow.TPIdentity;

			iLangl.LanguageWire.DAL.iLanglDAL.DALFacade.Instance.ContactDAL.UpdateContactReference(contact.Id, customerId, null);
			contact.TPIdentity = customerId.ToString();
		}

		public Contact GetResponsiblePerson(int jobId)
		{
			return SettingsManager.Instance.GetDefaultContact();
		}

		#endregion
	}
}
